//
//  FGRecordTopView.m
//  VocieRecorder
//
//  Created by Fengur on 16/9/1.
//  Copyright © 2016年 code.uworks.fengur. All rights reserved.
//

#import "FGRecordTopView.h"
#import "NSString+DateTool.h"

@interface FGRecordTopView () {
    UIView *_lineView;
}

@end

@implementation FGRecordTopView

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupControls];
        [self setConrolsLayOut];
    }
    return self;
}

- (void)setupControls {
    self.backgroundColor = [UIColor whiteColor];
    _dateView = [[UIView alloc]
        initWithFrame:CGRectMake(0, 0, ScreenWidth, [FGSizeTool heightWithSize6:60])];
    [self addSubview:_dateView];

    _dateLabel = [[UILabel alloc] init];
    _dateLabel.textAlignment = NSTextAlignmentLeft;
    _dateLabel.font = AvenirMedium(15.f);
    _dateLabel.text = [NSString currentDate];
    _dateLabel.textColor = [UIColor blackColor];
    [_dateView addSubview:_dateLabel];

    _voiceformatLabel = [[UILabel alloc] init];
    _voiceformatLabel.textAlignment = NSTextAlignmentRight;
    _voiceformatLabel.textColor = [UIColor grayColor];
    _voiceformatLabel.text = @"AAC";
    _voiceformatLabel.font = _dateLabel.font;
    [_dateView addSubview:_voiceformatLabel];

    _lineView = [[UIView alloc] init];
    _lineView.backgroundColor = [UIColor grayColor];
    [_dateView addSubview:_lineView];

    _countTimeLabel = [[MZTimerLabel alloc] init];
    _countTimeLabel.timeFormat = @"HH:mm ss";
    _countTimeLabel.textAlignment = NSTextAlignmentCenter;
    _countTimeLabel.font = AvenirMedium(25.f);
    _countTimeLabel.timerType = MZTimerLabelTypeStopWatch;
    [self addSubview:_countTimeLabel];
}

- (void)setConrolsLayOut {
    [_dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(1);
        make.left.mas_equalTo(PADDING_CELL);
    }];

    [_voiceformatLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.right.mas_equalTo(-PADDING_CELL);
        make.bottom.mas_equalTo(_dateLabel.mas_bottom);

    }];

    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(PADDING_CELL);
        make.right.mas_equalTo(-PADDING_CELL);
        make.bottom.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
    }];

    [_countTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_dateView.height);
        make.bottom.mas_equalTo(0);
        make.width.mas_equalTo(self.width);
    }];
}

- (void)startRecording {
    [_countTimeLabel start];
}

- (void)endRecording {
    [_countTimeLabel pause];
}

@end
